package com.suixinsanren.algorithm.sort.bubble.demo05;

import java.util.Objects;

public class BubbleSort {

    public static int[] sort(int[] arr) {
        if (Objects.isNull(arr)) {
            System.out.println("待排序数组为空");
        }

        int temp;
        for (int i = 0; i < arr.length - 1; i++) {
            for (int j = 0; j < arr.length - i - 1; j++) {
                if (arr[j] > arr[j + 1]) {
                    temp = arr[j];
                    arr[j] = arr[j + 1];
                    arr[j + 1] = temp;
                }
            }
        }

        return arr;
    }
}
